/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   Module Name          : com.yaodian100.ec.generatepage.web.IdxGoldFourAdvAction
   Module Description   :

   Date Created      : 2010/3/8
   Original Author   : apple.chang
   Team              : yaodian100
   ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   MODIFICATION HISTORY
   ------------------------------------------------------------------------------
   Date Modified       Modified by       Comments
   ------------------------------------------------------------------------------
   ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
package com.yaodian100.ec.generatepage.web;

import java.io.File;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Properties;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.FastDateFormat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.Preparable;
import com.yaodian100.core.common.exception.CoreException;
import com.yaodian100.core.common.utils.DateUtil;
import com.yaodian100.ec.common.EcConstant;
import com.yaodian100.ec.generate.entity.EventImage;
import com.yaodian100.ec.generate.entity.GenerateAdvertise;
import com.yaodian100.ec.generate.entity.GenerateContent;
import com.yaodian100.ec.generate.entity.GeneratePosition;
import com.yaodian100.ec.generate.service.GenerateService;

/**
 * 
 * @author apple.chang
 * 
 */
public class IdxGoldFourAdvAction extends ActionSupport implements Preparable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 8280417163118221483L;

	private final Logger logger = LoggerFactory.getLogger(IdxGoldFourAdvAction.class);
	private GenerateService generateService;
	private GenerateAdvertise advertise;
	private GeneratePosition position;
	private GenerateContent content;
	private StringBuilder contents;
	private String advId;
	private String advName;
	private String advType = "IDX_GOLDFOUR";
	private String advStatus;
	private String startDate;
	private String endDate;
	private String startTime;
	private String endTime;

	private File tab1Img1 = null;
	private String tab1Img1Name;
	private String tab1Img1Link;
	private String tab1Img1Folder;
	private File tab1Img2 = null;
	private String tab1Img2Name;
	private String tab1Img2Link;
	private String tab1Img2Folder;
	private File tab1Img3 = null;
	private String tab1Img3Name;
	private String tab1Img3Link;
	private String tab1Img3Folder;
	private File tab1Img4 = null;
	private String tab1Img4Name;
	private String tab1Img4Link;
	private String tab1Img4Folder;
	private String tab1Img1adWord;
	private String tab1Img2adWord;
	private String tab1Img3adWord;
	private String tab1Img4adWord;

	private File tab2Img1 = null;
	private String tab2Img1Name;
	private String tab2Img1Link;
	private String tab2Img1Folder;
	private File tab2Img2 = null;
	private String tab2Img2Name;
	private String tab2Img2Link;
	private String tab2Img2Folder;
	private File tab2Img3 = null;
	private String tab2Img3Name;
	private String tab2Img3Link;
	private String tab2Img3Folder;
	private File tab2Img4 = null;
	private String tab2Img4Name;
	private String tab2Img4Link;
	private String tab2Img4Folder;
	private String tab2Img1adWord;
	private String tab2Img2adWord;
	private String tab2Img3adWord;
	private String tab2Img4adWord;

	private File tab3Img1 = null;
	private String tab3Img1Name;
	private String tab3Img1Link;
	private String tab3Img1Folder;
	private File tab3Img2 = null;
	private String tab3Img2Name;
	private String tab3Img2Link;
	private String tab3Img2Folder;
	private File tab3Img3 = null;
	private String tab3Img3Name;
	private String tab3Img3Link;
	private String tab3Img3Folder;
	private File tab3Img4 = null;
	private String tab3Img4Name;
	private String tab3Img4Link;
	private String tab3Img4Folder;
	private String tab3Img1adWord;
	private String tab3Img2adWord;
	private String tab3Img3adWord;
	private String tab3Img4adWord;

	private EventImage eventImage = null;
	private final DateFormat PATTERN_DATE_FORMAT = new SimpleDateFormat(EcConstant.PATTERN_TIMESTAMP);

	/**
	 * 新增首頁黄金四格商品
	 * 
	 * @return
	 */
	public String addIdxGoldFourAdv() {
		advId = "";
		return "editIdxGoldFourAdv";
	}

	/**
	 * 新增首頁黄金四格商品V2
	 * 
	 * @return
	 */
	public String addIdxGoldFourAdvV2() {
		advId = "";
		advType = "IDX_GOLDFOUR_V2";
		return "editIdxGoldFourAdvV2";
	}

	private String checkURL(String url) {
		if (!(url.substring(0, 5).equals("https") || url.substring(0, 4).equals("http")
				|| url.substring(0, 3).equals("ftp") || url.substring(0, 4).equals("rtsp") || url.substring(0, 3).equals("mms"))) {
			return "http://" + url;
		}
		return url;
	}

	/**
	 * 编辑首页类别促销版位
	 * 
	 * @return
	 * @throws Exception
	 */
	public String editIdxGoldFourAdv() throws Exception {
		initVariables();
		advertise = generateService.get(Long.parseLong(advId));
		position = generateService.getGeneratePositionByAdvId(Long.parseLong(advId)).get(0);
		content = generateService.getGenerateContentByAdvId(Long.parseLong(advId)).get(0);
		advStatus = advertise.getAdvStatus();
		advType = advertise.getAdvType();
		advName = advertise.getAdvName();
		startDate = FastDateFormat.getInstance(EcConstant.PATTERN_DATE).format(advertise.getStartDate());
		endDate = FastDateFormat.getInstance(EcConstant.PATTERN_DATE).format(advertise.getEndDate());
		readPropertise(content);
		return "editIdxGoldFourAdv";
	}

	/**
	 * 编辑首页类别促销版位V2
	 * 
	 * @return
	 * @throws Exception
	 */
	public String editIdxGoldFourAdvV2() throws Exception {
		initVariables();
		advertise = generateService.get(Long.parseLong(advId));
		position = generateService.getGeneratePositionByAdvId(Long.parseLong(advId)).get(0);
		content = generateService.getGenerateContentByAdvId(Long.parseLong(advId)).get(0);
		advStatus = advertise.getAdvStatus();
		advType = advertise.getAdvType();
		advName = advertise.getAdvName();
		startDate = FastDateFormat.getInstance(EcConstant.PATTERN_DATE).format(advertise.getStartDate());
		endDate = FastDateFormat.getInstance(EcConstant.PATTERN_DATE).format(advertise.getEndDate());
		startTime = FastDateFormat.getInstance("HH:mm").format(advertise.getStartDate());
		endTime = FastDateFormat.getInstance("HH:mm").format(advertise.getEndDate());
		readPropertise(content);
		return "editIdxGoldFourAdvV2";
	}

	/**
	 * @return the advId
	 */
	public String getAdvId() {
		return advId;
	}

	/**
	 * @return the advName
	 */
	public String getAdvName() {
		return advName;
	}

	/**
	 * @return the advStatus
	 */
	public String getAdvStatus() {
		return advStatus;
	}

	/**
	 * @return the advType
	 */
	public String getAdvType() {
		return advType;
	}

	/**
	 * @return the content
	 */
	public GenerateContent getContent() {
		return content;
	}

	/**
	 * @return the endDate
	 */
	public String getEndDate() {
		return endDate;
	}

	public String getEndTime() {
		return endTime;
	}

	/**
	 * @return the startDate
	 */
	public String getStartDate() {
		return startDate;
	}

	public String getStartTime() {
		return startTime;
	}

	/**
	 * @return the tab1Img1
	 */
	public File getTab1Img1() {
		return tab1Img1;
	}

	/**
	 * @return the tab1Img1Folder
	 */
	public String getTab1Img1Folder() {
		return tab1Img1Folder;
	}

	/**
	 * @return the tab1Img1Link
	 */
	public String getTab1Img1Link() {
		return tab1Img1Link;
	}

	/**
	 * @return the tab1Img1Name
	 */
	public String getTab1Img1Name() {
		return tab1Img1Name;
	}

	/**
	 * @return the tab1Img2
	 */
	public File getTab1Img2() {
		return tab1Img2;
	}

	/**
	 * @return the tab1Img2Folder
	 */
	public String getTab1Img2Folder() {
		return tab1Img2Folder;
	}

	/**
	 * @return the tab1Img2Link
	 */
	public String getTab1Img2Link() {
		return tab1Img2Link;
	}

	/**
	 * @return the tab1Img2Name
	 */
	public String getTab1Img2Name() {
		return tab1Img2Name;
	}

	/**
	 * @return the tab1Img3
	 */
	public File getTab1Img3() {
		return tab1Img3;
	}

	/**
	 * @return the tab1Img3Folder
	 */
	public String getTab1Img3Folder() {
		return tab1Img3Folder;
	}

	/**
	 * @return the tab1Img3Link
	 */
	public String getTab1Img3Link() {
		return tab1Img3Link;
	}

	/**
	 * @return the tab1Img3Name
	 */
	public String getTab1Img3Name() {
		return tab1Img3Name;
	}

	/**
	 * @return the tab1Img4
	 */
	public File getTab1Img4() {
		return tab1Img4;
	}

	/**
	 * @return the tab1Img4Folder
	 */
	public String getTab1Img4Folder() {
		return tab1Img4Folder;
	}

	/**
	 * @return the tab1Img4Link
	 */
	public String getTab1Img4Link() {
		return tab1Img4Link;
	}

	/**
	 * @return the tab1Img4Name
	 */
	public String getTab1Img4Name() {
		return tab1Img4Name;
	}

	/**
	 * @return the tab2Img1
	 */
	public File getTab2Img1() {
		return tab2Img1;
	}

	/**
	 * @return the tab2Img1Folder
	 */
	public String getTab2Img1Folder() {
		return tab2Img1Folder;
	}

	/**
	 * @return the tab2Img1Link
	 */
	public String getTab2Img1Link() {
		return tab2Img1Link;
	}

	/**
	 * @return the tab2Img1Name
	 */
	public String getTab2Img1Name() {
		return tab2Img1Name;
	}

	/**
	 * @return the tab2Img2
	 */
	public File getTab2Img2() {
		return tab2Img2;
	}

	/**
	 * @return the tab2Img2Folder
	 */
	public String getTab2Img2Folder() {
		return tab2Img2Folder;
	}

	/**
	 * @return the tab2Img2Link
	 */
	public String getTab2Img2Link() {
		return tab2Img2Link;
	}

	/**
	 * @return the tab2Img2Name
	 */
	public String getTab2Img2Name() {
		return tab2Img2Name;
	}

	/**
	 * @return the tab2Img3
	 */
	public File getTab2Img3() {
		return tab2Img3;
	}

	/**
	 * @return the tab2Img3Folder
	 */
	public String getTab2Img3Folder() {
		return tab2Img3Folder;
	}

	/**
	 * @return the tab2Img3Link
	 */
	public String getTab2Img3Link() {
		return tab2Img3Link;
	}

	/**
	 * @return the tab2Img3Name
	 */
	public String getTab2Img3Name() {
		return tab2Img3Name;
	}

	/**
	 * @return the tab2Img4
	 */
	public File getTab2Img4() {
		return tab2Img4;
	}

	/**
	 * @return the tab2Img4Folder
	 */
	public String getTab2Img4Folder() {
		return tab2Img4Folder;
	}

	/**
	 * @return the tab2Img4Link
	 */
	public String getTab2Img4Link() {
		return tab2Img4Link;
	}

	/**
	 * @return the tab2Img4Name
	 */
	public String getTab2Img4Name() {
		return tab2Img4Name;
	}

	/**
	 * @return the tab3Img1
	 */
	public File getTab3Img1() {
		return tab3Img1;
	}

	/**
	 * @return the tab3Img1Folder
	 */
	public String getTab3Img1Folder() {
		return tab3Img1Folder;
	}

	/**
	 * @return the tab3Img1Link
	 */
	public String getTab3Img1Link() {
		return tab3Img1Link;
	}

	/**
	 * @return the tab3Img1Name
	 */
	public String getTab3Img1Name() {
		return tab3Img1Name;
	}

	/**
	 * @return the tab3Img2
	 */
	public File getTab3Img2() {
		return tab3Img2;
	}

	/**
	 * @return the tab3Img2Folder
	 */
	public String getTab3Img2Folder() {
		return tab3Img2Folder;
	}

	/**
	 * @return the tab3Img2Link
	 */
	public String getTab3Img2Link() {
		return tab3Img2Link;
	}

	/**
	 * @return the tab3Img2Name
	 */
	public String getTab3Img2Name() {
		return tab3Img2Name;
	}

	/**
	 * @return the tab3Img3
	 */
	public File getTab3Img3() {
		return tab3Img3;
	}

	/**
	 * @return the tab3Img3Folder
	 */
	public String getTab3Img3Folder() {
		return tab3Img3Folder;
	}

	/**
	 * @return the tab3Img3Link
	 */
	public String getTab3Img3Link() {
		return tab3Img3Link;
	}

	/**
	 * @return the tab3Img3Name
	 */
	public String getTab3Img3Name() {
		return tab3Img3Name;
	}

	/**
	 * @return the tab3Img4
	 */
	public File getTab3Img4() {
		return tab3Img4;
	}

	/**
	 * @return the tab3Img4Folder
	 */
	public String getTab3Img4Folder() {
		return tab3Img4Folder;
	}

	/**
	 * @return the tab3Img4Link
	 */
	public String getTab3Img4Link() {
		return tab3Img4Link;
	}

	/**
	 * @return the tab3Img4Name
	 */
	public String getTab3Img4Name() {
		return tab3Img4Name;
	}

	private boolean idxGoldFourAdvValidate() throws CoreException, ParseException, IOException {
		/**************************** 必填栏位 ****************************/
		logger.info("advName = " + advName);

		if (StringUtils.isBlank(advName)) {
			addFieldError("advName", "请输入广告名称");
		}

		if (StringUtils.isBlank(startDate)) {
			addFieldError("startDate", "请输入起始日期");
		}

		if (StringUtils.isBlank(endDate)) {
			addFieldError("endDate", "请输入结束日期");
		}

		if (StringUtils.isBlank(tab1Img1Name)) {
			addFieldError("tab1Img1Name", "請輸入tab1 img1 name");
		}

		if (StringUtils.isBlank(tab1Img1Link)) {
			addFieldError("tab1Img1Link", "請輸入tab1 img1 link");
		}

		if (StringUtils.isBlank(tab1Img2Name)) {
			addFieldError("tab1Img2Name", "請輸入tab1 img2 name");
		}

		if (StringUtils.isBlank(tab1Img2Link)) {
			addFieldError("tab1Img2Link", "請輸入tab1 img2 link");
		}

		if (StringUtils.isBlank(tab1Img3Name)) {
			addFieldError("tab1Img3Name", "請輸入tab1 img3 name");
		}

		if (StringUtils.isBlank(tab1Img3Link)) {
			addFieldError("tab1Img3Link", "請輸入tab1 img3 link");
		}

		if (StringUtils.isBlank(tab1Img4Name)) {
			addFieldError("tab1Img4Name", "請輸入tab1 img4 name");
		}

		if (StringUtils.isBlank(tab1Img4Link)) {
			addFieldError("tab1Img4Link", "請輸入tab1 img4 link");
		}

		if (StringUtils.isBlank(tab2Img1Name)) {
			addFieldError("tab2Img1Name", "請輸入tab2 img1 name");
		}

		if (StringUtils.isBlank(tab2Img1Link)) {
			addFieldError("tab2Img1Link", "請輸入tab2 img1 link");
		}

		if (StringUtils.isBlank(tab2Img2Name)) {
			addFieldError("tab2Img2Name", "請輸入tab2 img2 name");
		}

		if (StringUtils.isBlank(tab2Img2Link)) {
			addFieldError("tab2Img2Link", "請輸入tab2 img2 link");
		}

		if (StringUtils.isBlank(tab2Img3Name)) {
			addFieldError("tab2Img3Name", "請輸入tab2 img3 name");
		}

		if (StringUtils.isBlank(tab2Img3Link)) {
			addFieldError("tab2Img3Link", "請輸入tab2 img3 link");
		}

		if (StringUtils.isBlank(tab2Img4Name)) {
			addFieldError("tab2Img4Name", "請輸入tab2 img4 name");
		}

		if (StringUtils.isBlank(tab2Img4Link)) {
			addFieldError("tab2Img4Link", "請輸入tab2 img4 link");
		}

		if (StringUtils.isBlank(tab3Img1Name)) {
			addFieldError("tab3Img1Name", "請輸入tab3 img1 name");
		}

		if (StringUtils.isBlank(tab3Img1Link)) {
			addFieldError("tab3Img1Link", "請輸入tab3 img1 link");
		}

		if (StringUtils.isBlank(tab3Img2Name)) {
			addFieldError("tab3Img2Name", "請輸入tab3 img2 name");
		}

		if (StringUtils.isBlank(tab3Img2Link)) {
			addFieldError("tab3Img2Link", "請輸入tab3 img2 link");
		}

		if (StringUtils.isBlank(tab3Img3Name)) {
			addFieldError("tab3Img3Name", "請輸入tab3 img3 name");
		}

		if (StringUtils.isBlank(tab3Img3Link)) {
			addFieldError("tab3Img3Link", "請輸入tab3 img3 link");
		}

		if (StringUtils.isBlank(tab3Img4Name)) {
			addFieldError("tab3Img4Name", "請輸入tab3 img4 name");
		}

		if (StringUtils.isBlank(tab3Img4Link)) {
			addFieldError("tab3Img4Link", "請輸入tab3 img4 link");
		}

		if (getFieldErrors().isEmpty()) {
			return true;
		} else {
			return false;
		}
	}

	/**
	 * 初始化变数值
	 */
	void initVariables() {
		advertise = new GenerateAdvertise();
		position = new GeneratePosition();
		content = new GenerateContent();

		tab1Img1 = null;
		tab1Img1Name = "";
		tab1Img1Link = "";
		tab1Img1Folder = "";
		tab1Img2 = null;
		tab1Img2Name = "";
		tab1Img2Link = "";
		tab1Img2Folder = "";
		tab1Img3 = null;
		tab1Img3Name = "";
		tab1Img3Link = "";
		tab1Img3Folder = "";
		tab1Img4 = null;
		tab1Img4Name = "";
		tab1Img4Link = "";
		tab1Img4Folder = "";

		tab2Img1 = null;
		tab2Img1Name = "";
		tab2Img1Link = "";
		tab2Img1Folder = "";
		tab2Img2 = null;
		tab2Img2Name = "";
		tab2Img2Link = "";
		tab2Img2Folder = "";
		tab2Img3 = null;
		tab2Img3Name = "";
		tab2Img3Link = "";
		tab2Img3Folder = "";
		tab2Img4 = null;
		tab2Img4Name = "";
		tab2Img4Link = "";
		tab2Img4Folder = "";

		tab3Img1 = null;
		tab3Img1Name = "";
		tab3Img1Link = "";
		tab3Img1Folder = "";
		tab3Img2 = null;
		tab3Img2Name = "";
		tab3Img2Link = "";
		tab3Img2Folder = "";
		tab3Img3 = null;
		tab3Img3Name = "";
		tab3Img3Link = "";
		tab3Img3Folder = "";
		tab3Img4 = null;
		tab3Img4Name = "";
		tab3Img4Link = "";
		tab3Img4Folder = "";

		startDate = "";
		endDate = "";
		startTime = "";
		endTime = "";
	}

	public void prepare() throws Exception {
		// TODO Auto-generated method stub
		clearErrorsAndMessages();
	}

	/**
	 * 從db讀取propertise資料
	 * 
	 * @param content
	 * @throws IOException
	 */
	void readPropertise(GenerateContent content) throws IOException {
		Properties prop = new Properties();
		Reader reader = new StringReader(content.getContents());
		prop.load(reader);
		reader.close();
		tab1Img1Name = StringUtils.defaultString(prop.get("tab1Img1Name").toString());
		tab1Img1Link = StringUtils.defaultString(prop.get("tab1Img1Link").toString(), "");
		tab1Img1Folder = StringUtils.defaultString(prop.get("tab1Img1Folder").toString(), "");
		tab1Img2Name = StringUtils.defaultString(prop.get("tab1Img2Name").toString());
		tab1Img2Link = StringUtils.defaultString(prop.get("tab1Img2Link").toString(), "");
		tab1Img2Folder = StringUtils.defaultString(prop.get("tab1Img2Folder").toString(), "");
		tab1Img3Name = StringUtils.defaultString(prop.get("tab1Img3Name").toString());
		tab1Img3Link = StringUtils.defaultString(prop.get("tab1Img3Link").toString(), "");
		tab1Img3Folder = StringUtils.defaultString(prop.get("tab1Img3Folder").toString(), "");
		tab1Img4Name = StringUtils.defaultString(prop.get("tab1Img4Name").toString());
		tab1Img4Link = StringUtils.defaultString(prop.get("tab1Img4Link").toString(), "");
		tab1Img4Folder = StringUtils.defaultString(prop.get("tab1Img4Folder").toString(), "");

		tab2Img1Name = StringUtils.defaultString(prop.get("tab2Img1Name").toString(), "");
		tab2Img1Link = StringUtils.defaultString(prop.get("tab2Img1Link").toString(), "");
		tab2Img1Folder = StringUtils.defaultString(prop.get("tab2Img1Folder").toString(), "");
		tab2Img2Name = StringUtils.defaultString(prop.get("tab2Img2Name").toString());
		tab2Img2Link = StringUtils.defaultString(prop.get("tab2Img2Link").toString(), "");
		tab2Img2Folder = StringUtils.defaultString(prop.get("tab2Img2Folder").toString(), "");
		tab2Img3Name = StringUtils.defaultString(prop.get("tab2Img3Name").toString());
		tab2Img3Link = StringUtils.defaultString(prop.get("tab2Img3Link").toString(), "");
		tab2Img3Folder = StringUtils.defaultString(prop.get("tab2Img3Folder").toString(), "");
		tab2Img4Name = StringUtils.defaultString(prop.get("tab2Img4Name").toString());
		tab2Img4Link = StringUtils.defaultString(prop.get("tab2Img4Link").toString(), "");
		tab2Img4Folder = StringUtils.defaultString(prop.get("tab2Img4Folder").toString(), "");

		tab3Img1Name = StringUtils.defaultString(prop.get("tab3Img1Name").toString(), "");
		tab3Img1Link = StringUtils.defaultString(prop.get("tab3Img1Link").toString(), "");
		tab3Img1Folder = StringUtils.defaultString(prop.get("tab3Img1Folder").toString(), "");
		tab3Img2Name = StringUtils.defaultString(prop.get("tab3Img2Name").toString());
		tab3Img2Link = StringUtils.defaultString(prop.get("tab3Img2Link").toString(), "");
		tab3Img2Folder = StringUtils.defaultString(prop.get("tab3Img2Folder").toString(), "");
		tab3Img3Name = StringUtils.defaultString(prop.get("tab3Img3Name").toString());
		tab3Img3Link = StringUtils.defaultString(prop.get("tab3Img3Link").toString(), "");
		tab3Img3Folder = StringUtils.defaultString(prop.get("tab3Img3Folder").toString(), "");
		tab3Img4Name = StringUtils.defaultString(prop.get("tab3Img4Name").toString());
		tab3Img4Link = StringUtils.defaultString(prop.get("tab3Img4Link").toString(), "");
		tab3Img4Folder = StringUtils.defaultString(prop.get("tab3Img4Folder").toString(), "");

		if (prop.containsKey("tab1Img1adWord")) {
			tab1Img1adWord = StringUtils.defaultString(prop.get("tab1Img1adWord").toString(), "");
		}
		if (prop.containsKey("tab1Img2adWord")) {
			tab1Img2adWord = StringUtils.defaultString(prop.get("tab1Img2adWord").toString(), "");
		}
		if (prop.containsKey("tab1Img3adWord")) {
			tab1Img3adWord = StringUtils.defaultString(prop.get("tab1Img3adWord").toString(), "");
		}
		if (prop.containsKey("tab1Img4adWord")) {
			tab1Img4adWord = StringUtils.defaultString(prop.get("tab1Img4adWord").toString(), "");
		}

		if (prop.containsKey("tab2Img1adWord")) {
			tab2Img1adWord = StringUtils.defaultString(prop.get("tab2Img1adWord").toString(), "");
		}
		if (prop.containsKey("tab2Img2adWord")) {
			tab2Img2adWord = StringUtils.defaultString(prop.get("tab2Img2adWord").toString(), "");
		}
		if (prop.containsKey("tab2Img3adWord")) {
			tab2Img3adWord = StringUtils.defaultString(prop.get("tab2Img3adWord").toString(), "");
		}
		if (prop.containsKey("tab2Img4adWord")) {
			tab2Img4adWord = StringUtils.defaultString(prop.get("tab2Img4adWord").toString(), "");
		}

		if (prop.containsKey("tab3Img1adWord")) {
			tab3Img1adWord = StringUtils.defaultString(prop.get("tab3Img1adWord").toString(), "");
		}
		if (prop.containsKey("tab3Img2adWord")) {
			tab3Img2adWord = StringUtils.defaultString(prop.get("tab3Img2adWord").toString(), "");
		}
		if (prop.containsKey("tab3Img3adWord")) {
			tab3Img3adWord = StringUtils.defaultString(prop.get("tab3Img3adWord").toString(), "");
		}
		if (prop.containsKey("tab3Img4adWord")) {
			tab3Img4adWord = StringUtils.defaultString(prop.get("tab3Img4adWord").toString(), "");
		}

	}

	/**
	 * 储存广告
	 * 
	 * @return
	 * @throws Exception
	 * @throws IOException
	 * @throws ParseException
	 * @throws CoreException
	 * @throws NumberFormatException
	 */
	public String saveIdxGoldFourAdv() throws NumberFormatException, CoreException, ParseException, IOException,
			Exception {
		boolean result = false;
		if (idxGoldFourAdvValidate()) {
			contents = new StringBuilder("");
			String today = FastDateFormat.getInstance("yyyyMMdd").format(DateUtil.getToday().getTime());
			// upload file
			if (GenerateHelper.mkDir(advType)) {
				if (StringUtils.isBlank(advId)) {// add
					eventImage = saveImgFile(tab1Img1, tab1Img1Name, advType);
					if (null != eventImage) {
						contents.append("tab1Img1Name=").append(eventImage.getUuid()).append(eventImage.getImgType()).append("\n")
								.append("tab1Img1Folder=").append(today).append("\n");
					}

					eventImage = saveImgFile(tab1Img2, tab1Img2Name, advType);
					if (null != eventImage) {
						contents.append("tab1Img2Name=").append(eventImage.getUuid()).append(eventImage.getImgType()).append("\n")
								.append("tab1Img2Folder=").append(today).append("\n");
					}

					eventImage = saveImgFile(tab1Img3, tab1Img3Name, advType);
					if (null != eventImage) {
						contents.append("tab1Img3Name=").append(eventImage.getUuid()).append(eventImage.getImgType()).append("\n")
								.append("tab1Img3Folder=").append(today).append("\n");
					}

					eventImage = saveImgFile(tab1Img4, tab1Img4Name, advType);
					if (null != eventImage) {
						contents.append("tab1Img4Name=").append(eventImage.getUuid()).append(eventImage.getImgType()).append("\n")
								.append("tab1Img4Folder=").append(today).append("\n");
					}

					eventImage = saveImgFile(tab2Img1, tab2Img1Name, advType);
					if (null != eventImage) {
						contents.append("tab2Img1Name=").append(eventImage.getUuid()).append(eventImage.getImgType()).append("\n")
								.append("tab2Img1Folder=").append(today).append("\n");
					}

					eventImage = saveImgFile(tab2Img2, tab2Img2Name, advType);
					if (null != eventImage) {
						contents.append("tab2Img2Name=").append(eventImage.getUuid()).append(eventImage.getImgType()).append("\n")
								.append("tab2Img2Folder=").append(today).append("\n");
					}

					eventImage = saveImgFile(tab2Img3, tab2Img3Name, advType);
					if (null != eventImage) {
						contents.append("tab2Img3Name=").append(eventImage.getUuid()).append(eventImage.getImgType()).append("\n")
								.append("tab2Img3Folder=").append(today).append("\n");
					}

					eventImage = saveImgFile(tab2Img4, tab2Img4Name, advType);
					if (null != eventImage) {
						contents.append("tab2Img4Name=").append(eventImage.getUuid()).append(eventImage.getImgType()).append("\n")
								.append("tab2Img4Folder=").append(today).append("\n");
					}

					eventImage = saveImgFile(tab3Img1, tab3Img1Name, advType);
					if (null != eventImage) {
						contents.append("tab3Img1Name=").append(eventImage.getUuid()).append(eventImage.getImgType()).append("\n")
								.append("tab3Img1Folder=").append(today).append("\n");
					}

					eventImage = saveImgFile(tab3Img2, tab3Img2Name, advType);
					if (null != eventImage) {
						contents.append("tab3Img2Name=").append(eventImage.getUuid()).append(eventImage.getImgType()).append("\n")
								.append("tab3Img2Folder=").append(today).append("\n");
					}

					eventImage = saveImgFile(tab3Img3, tab3Img3Name, advType);
					if (null != eventImage) {
						contents.append("tab3Img3Name=").append(eventImage.getUuid()).append(eventImage.getImgType()).append("\n")
								.append("tab3Img3Folder=").append(today).append("\n");
					}

					eventImage = saveImgFile(tab3Img4, tab3Img4Name, advType);
					if (null != eventImage) {
						contents.append("tab3Img4Name=").append(eventImage.getUuid()).append(eventImage.getImgType()).append("\n")
								.append("tab3Img4Folder=").append(today).append("\n");
					}

				} else {// update
					// 1
					if (null == tab1Img1) {
						contents.append("tab1Img1Name=").append(tab1Img1Name).append("\n").append("tab1Img1Folder=").append(
								tab1Img1Folder).append("\n");
					} else {
						eventImage = saveImgFile(tab1Img1, tab1Img1Name, advType);
						if (null != eventImage) {
							contents.append("tab1Img1Name=").append(eventImage.getUuid()).append(eventImage.getImgType())
									.append("\n").append("tab1Img1Folder=").append(today).append("\n");
						}
					}
					if (null == tab1Img2) {
						contents.append("tab1Img2Name=").append(tab1Img2Name).append("\n").append("tab1Img2Folder=").append(
								tab1Img2Folder).append("\n");
					} else {
						eventImage = saveImgFile(tab1Img2, tab1Img2Name, advType);
						if (null != eventImage) {
							contents.append("tab1Img2Name=").append(eventImage.getUuid()).append(eventImage.getImgType())
									.append("\n").append("tab1Img2Folder=").append(today).append("\n");
						}
					}

					if (null == tab1Img3) {
						contents.append("tab1Img3Name=").append(tab1Img3Name).append("\n").append("tab1Img3Folder=").append(
								tab1Img3Folder).append("\n");
					} else {
						eventImage = saveImgFile(tab1Img3, tab1Img3Name, advType);
						if (null != eventImage) {
							contents.append("tab1Img3Name=").append(eventImage.getUuid()).append(eventImage.getImgType())
									.append("\n").append("tab1Img3Folder=").append(today).append("\n");
						}
					}

					if (null == tab1Img4) {
						contents.append("tab1Img4Name=").append(tab1Img4Name).append("\n").append("tab1Img4Folder=").append(
								tab1Img4Folder).append("\n");
					} else {
						eventImage = saveImgFile(tab1Img4, tab1Img4Name, advType);
						if (null != eventImage) {
							contents.append("tab1Img4Name=").append(eventImage.getUuid()).append(eventImage.getImgType())
									.append("\n").append("tab1Img4Folder=").append(today).append("\n");
						}
					}

					// 2
					if (null == tab2Img1) {
						contents.append("tab2Img1Name=").append(tab2Img1Name).append("\n").append("tab2Img1Folder=").append(
								tab2Img1Folder).append("\n");
					} else {
						eventImage = saveImgFile(tab2Img1, tab2Img1Name, advType);
						if (null != eventImage) {
							contents.append("tab2Img1Name=").append(eventImage.getUuid()).append(eventImage.getImgType())
									.append("\n").append("tab2Img1Folder=").append(today).append("\n");
						}
					}
					if (null == tab2Img2) {
						contents.append("tab2Img2Name=").append(tab2Img2Name).append("\n").append("tab2Img2Folder=").append(
								tab2Img2Folder).append("\n");
					} else {
						eventImage = saveImgFile(tab2Img2, tab2Img2Name, advType);
						if (null != eventImage) {
							contents.append("tab2Img2Name=").append(eventImage.getUuid()).append(eventImage.getImgType())
									.append("\n").append("tab2Img2Folder=").append(today).append("\n");
						}
					}

					if (null == tab2Img3) {
						contents.append("tab2Img3Name=").append(tab2Img3Name).append("\n").append("tab2Img3Folder=").append(
								tab2Img3Folder).append("\n");
					} else {
						eventImage = saveImgFile(tab2Img3, tab2Img3Name, advType);
						if (null != eventImage) {
							contents.append("tab2Img3Name=").append(eventImage.getUuid()).append(eventImage.getImgType())
									.append("\n").append("tab2Img3Folder=").append(today).append("\n");
						}
					}

					if (null == tab2Img4) {
						contents.append("tab2Img4Name=").append(tab2Img4Name).append("\n").append("tab2Img4Folder=").append(
								tab2Img4Folder).append("\n");
					} else {
						eventImage = saveImgFile(tab2Img4, tab2Img4Name, advType);
						if (null != eventImage) {
							contents.append("tab2Img4Name=").append(eventImage.getUuid()).append(eventImage.getImgType())
									.append("\n").append("tab2Img4Folder=").append(today).append("\n");
						}
					}

					// 3
					if (null == tab3Img1) {
						contents.append("tab3Img1Name=").append(tab3Img1Name).append("\n").append("tab3Img1Folder=").append(
								tab3Img1Folder).append("\n");
					} else {
						eventImage = saveImgFile(tab3Img1, tab3Img1Name, advType);
						if (null != eventImage) {
							contents.append("tab3Img1Name=").append(eventImage.getUuid()).append(eventImage.getImgType())
									.append("\n").append("tab3Img1Folder=").append(today).append("\n");
						}
					}
					if (null == tab3Img2) {
						contents.append("tab3Img2Name=").append(tab3Img2Name).append("\n").append("tab3Img2Folder=").append(
								tab3Img2Folder).append("\n");
					} else {
						eventImage = saveImgFile(tab3Img2, tab3Img2Name, advType);
						if (null != eventImage) {
							contents.append("tab3Img2Name=").append(eventImage.getUuid()).append(eventImage.getImgType())
									.append("\n").append("tab3Img2Folder=").append(today).append("\n");
						}
					}

					if (null == tab3Img3) {
						contents.append("tab3Img3Name=").append(tab3Img3Name).append("\n").append("tab3Img3Folder=").append(
								tab3Img3Folder).append("\n");
					} else {
						eventImage = saveImgFile(tab3Img3, tab3Img3Name, advType);
						if (null != eventImage) {
							contents.append("tab3Img3Name=").append(eventImage.getUuid()).append(eventImage.getImgType())
									.append("\n").append("tab3Img3Folder=").append(today).append("\n");
						}
					}

					if (null == tab3Img4) {
						contents.append("tab3Img4Name=").append(tab3Img4Name).append("\n").append("tab3Img4Folder=").append(
								tab3Img4Folder).append("\n");
					} else {
						eventImage = saveImgFile(tab3Img4, tab3Img4Name, advType);
						if (null != eventImage) {
							contents.append("tab3Img4Name=").append(eventImage.getUuid()).append(eventImage.getImgType())
									.append("\n").append("tab3Img4Folder=").append(today).append("\n");
						}
					}
				}

				contents.append("tab1Img1Link=").append(checkURL(tab1Img1Link)).append("\n");
				contents.append("tab1Img2Link=").append(checkURL(tab1Img2Link)).append("\n");
				contents.append("tab1Img3Link=").append(checkURL(tab1Img3Link)).append("\n");
				contents.append("tab1Img4Link=").append(checkURL(tab1Img4Link)).append("\n");

				contents.append("tab2Img1Link=").append(checkURL(tab2Img1Link)).append("\n");
				contents.append("tab2Img2Link=").append(checkURL(tab2Img2Link)).append("\n");
				contents.append("tab2Img3Link=").append(checkURL(tab2Img3Link)).append("\n");
				contents.append("tab2Img4Link=").append(checkURL(tab2Img4Link)).append("\n");

				contents.append("tab3Img1Link=").append(checkURL(tab3Img1Link)).append("\n");
				contents.append("tab3Img2Link=").append(checkURL(tab3Img2Link)).append("\n");
				contents.append("tab3Img3Link=").append(checkURL(tab3Img3Link)).append("\n");
				contents.append("tab3Img4Link=").append(checkURL(tab3Img4Link)).append("\n");

				if (StringUtils.isBlank(advId)) {
					advertise = new GenerateAdvertise();
					position = new GeneratePosition();
					content = new GenerateContent();
				} else {
					advertise = generateService.get(Long.parseLong(advId));
					position = generateService.getGeneratePositionByAdvId(Long.parseLong(advId)).get(0);
					content = generateService.getGenerateContentByAdvId(Long.parseLong(advId)).get(0);
				}
				// set advertise
				advertise.setAdvType(advType);
				advertise.setAdvName(advName.trim());
				advertise.setStartDate(EcConstant.PATTERN_DATE_FORMAT.parse(startDate));
				advertise.setEndDate(EcConstant.PATTERN_DATE_FORMAT.parse(endDate));
				advertise.setAdvStatus(advStatus);
				content.setContents(contents.toString());
				if (StringUtils.countMatches(content.getContents(), "Folder") == 12) {
					if (StringUtils.isBlank(advId)) {
						result = generateService.saveGenerateCombine(advertise, position, content);
					} else {
						result = generateService.updateGenerateCombine(advertise, position, content);
					}
				} else {
					result = false;
				}
				contents.setLength(0);
				if (!result) {
					return "editIdxGoldFourAdv";
				} else {
					return "listIdxAdv";
				}
			}
		}
		return "editIdxGoldFourAdv";
	}

	/**
	 * 储存广告
	 * 
	 * @return
	 * @throws Exception
	 * @throws IOException
	 * @throws ParseException
	 * @throws CoreException
	 * @throws NumberFormatException
	 */
	public String saveIdxGoldFourAdvV2() throws NumberFormatException, CoreException, ParseException, IOException,
			Exception {
		boolean result = false;
		if (idxGoldFourAdvValidate()) {
			contents = new StringBuilder("");
			String today = FastDateFormat.getInstance("yyyyMMdd").format(DateUtil.getToday().getTime());
			// upload file
			if (GenerateHelper.mkDir(advType)) {
				if (StringUtils.isBlank(advId)) {// add
					eventImage = saveImgFile(tab1Img1, tab1Img1Name, advType);
					if (null != eventImage) {
						contents.append("tab1Img1Name=").append(eventImage.getUuid()).append(eventImage.getImgType()).append("\n")
								.append("tab1Img1Folder=").append(today).append("\n");
					}

					eventImage = saveImgFile(tab1Img2, tab1Img2Name, advType);
					if (null != eventImage) {
						contents.append("tab1Img2Name=").append(eventImage.getUuid()).append(eventImage.getImgType()).append("\n")
								.append("tab1Img2Folder=").append(today).append("\n");
					}

					eventImage = saveImgFile(tab1Img3, tab1Img3Name, advType);
					if (null != eventImage) {
						contents.append("tab1Img3Name=").append(eventImage.getUuid()).append(eventImage.getImgType()).append("\n")
								.append("tab1Img3Folder=").append(today).append("\n");
					}

					eventImage = saveImgFile(tab1Img4, tab1Img4Name, advType);
					if (null != eventImage) {
						contents.append("tab1Img4Name=").append(eventImage.getUuid()).append(eventImage.getImgType()).append("\n")
								.append("tab1Img4Folder=").append(today).append("\n");
					}

					eventImage = saveImgFile(tab2Img1, tab2Img1Name, advType);
					if (null != eventImage) {
						contents.append("tab2Img1Name=").append(eventImage.getUuid()).append(eventImage.getImgType()).append("\n")
								.append("tab2Img1Folder=").append(today).append("\n");
					}

					eventImage = saveImgFile(tab2Img2, tab2Img2Name, advType);
					if (null != eventImage) {
						contents.append("tab2Img2Name=").append(eventImage.getUuid()).append(eventImage.getImgType()).append("\n")
								.append("tab2Img2Folder=").append(today).append("\n");
					}

					eventImage = saveImgFile(tab2Img3, tab2Img3Name, advType);
					if (null != eventImage) {
						contents.append("tab2Img3Name=").append(eventImage.getUuid()).append(eventImage.getImgType()).append("\n")
								.append("tab2Img3Folder=").append(today).append("\n");
					}

					eventImage = saveImgFile(tab2Img4, tab2Img4Name, advType);
					if (null != eventImage) {
						contents.append("tab2Img4Name=").append(eventImage.getUuid()).append(eventImage.getImgType()).append("\n")
								.append("tab2Img4Folder=").append(today).append("\n");
					}

					eventImage = saveImgFile(tab3Img1, tab3Img1Name, advType);
					if (null != eventImage) {
						contents.append("tab3Img1Name=").append(eventImage.getUuid()).append(eventImage.getImgType()).append("\n")
								.append("tab3Img1Folder=").append(today).append("\n");
					}

					eventImage = saveImgFile(tab3Img2, tab3Img2Name, advType);
					if (null != eventImage) {
						contents.append("tab3Img2Name=").append(eventImage.getUuid()).append(eventImage.getImgType()).append("\n")
								.append("tab3Img2Folder=").append(today).append("\n");
					}

					eventImage = saveImgFile(tab3Img3, tab3Img3Name, advType);
					if (null != eventImage) {
						contents.append("tab3Img3Name=").append(eventImage.getUuid()).append(eventImage.getImgType()).append("\n")
								.append("tab3Img3Folder=").append(today).append("\n");
					}

					eventImage = saveImgFile(tab3Img4, tab3Img4Name, advType);
					if (null != eventImage) {
						contents.append("tab3Img4Name=").append(eventImage.getUuid()).append(eventImage.getImgType()).append("\n")
								.append("tab3Img4Folder=").append(today).append("\n");
					}

				} else {// update
					// 1
					if (null == tab1Img1) {
						contents.append("tab1Img1Name=").append(tab1Img1Name).append("\n").append("tab1Img1Folder=").append(
								tab1Img1Folder).append("\n");
					} else {
						eventImage = saveImgFile(tab1Img1, tab1Img1Name, advType);
						if (null != eventImage) {
							contents.append("tab1Img1Name=").append(eventImage.getUuid()).append(eventImage.getImgType())
									.append("\n").append("tab1Img1Folder=").append(today).append("\n");
						}
					}
					if (null == tab1Img2) {
						contents.append("tab1Img2Name=").append(tab1Img2Name).append("\n").append("tab1Img2Folder=").append(
								tab1Img2Folder).append("\n");
					} else {
						eventImage = saveImgFile(tab1Img2, tab1Img2Name, advType);
						if (null != eventImage) {
							contents.append("tab1Img2Name=").append(eventImage.getUuid()).append(eventImage.getImgType())
									.append("\n").append("tab1Img2Folder=").append(today).append("\n");
						}
					}

					if (null == tab1Img3) {
						contents.append("tab1Img3Name=").append(tab1Img3Name).append("\n").append("tab1Img3Folder=").append(
								tab1Img3Folder).append("\n");
					} else {
						eventImage = saveImgFile(tab1Img3, tab1Img3Name, advType);
						if (null != eventImage) {
							contents.append("tab1Img3Name=").append(eventImage.getUuid()).append(eventImage.getImgType())
									.append("\n").append("tab1Img3Folder=").append(today).append("\n");
						}
					}

					if (null == tab1Img4) {
						contents.append("tab1Img4Name=").append(tab1Img4Name).append("\n").append("tab1Img4Folder=").append(
								tab1Img4Folder).append("\n");
					} else {
						eventImage = saveImgFile(tab1Img4, tab1Img4Name, advType);
						if (null != eventImage) {
							contents.append("tab1Img4Name=").append(eventImage.getUuid()).append(eventImage.getImgType())
									.append("\n").append("tab1Img4Folder=").append(today).append("\n");
						}
					}

					// 2
					if (null == tab2Img1) {
						contents.append("tab2Img1Name=").append(tab2Img1Name).append("\n").append("tab2Img1Folder=").append(
								tab2Img1Folder).append("\n");
					} else {
						eventImage = saveImgFile(tab2Img1, tab2Img1Name, advType);
						if (null != eventImage) {
							contents.append("tab2Img1Name=").append(eventImage.getUuid()).append(eventImage.getImgType())
									.append("\n").append("tab2Img1Folder=").append(today).append("\n");
						}
					}
					if (null == tab2Img2) {
						contents.append("tab2Img2Name=").append(tab2Img2Name).append("\n").append("tab2Img2Folder=").append(
								tab2Img2Folder).append("\n");
					} else {
						eventImage = saveImgFile(tab2Img2, tab2Img2Name, advType);
						if (null != eventImage) {
							contents.append("tab2Img2Name=").append(eventImage.getUuid()).append(eventImage.getImgType())
									.append("\n").append("tab2Img2Folder=").append(today).append("\n");
						}
					}

					if (null == tab2Img3) {
						contents.append("tab2Img3Name=").append(tab2Img3Name).append("\n").append("tab2Img3Folder=").append(
								tab2Img3Folder).append("\n");
					} else {
						eventImage = saveImgFile(tab2Img3, tab2Img3Name, advType);
						if (null != eventImage) {
							contents.append("tab2Img3Name=").append(eventImage.getUuid()).append(eventImage.getImgType())
									.append("\n").append("tab2Img3Folder=").append(today).append("\n");
						}
					}

					if (null == tab2Img4) {
						contents.append("tab2Img4Name=").append(tab2Img4Name).append("\n").append("tab2Img4Folder=").append(
								tab2Img4Folder).append("\n");
					} else {
						eventImage = saveImgFile(tab2Img4, tab2Img4Name, advType);
						if (null != eventImage) {
							contents.append("tab2Img4Name=").append(eventImage.getUuid()).append(eventImage.getImgType())
									.append("\n").append("tab2Img4Folder=").append(today).append("\n");
						}
					}

					// 3
					if (null == tab3Img1) {
						contents.append("tab3Img1Name=").append(tab3Img1Name).append("\n").append("tab3Img1Folder=").append(
								tab3Img1Folder).append("\n");
					} else {
						eventImage = saveImgFile(tab3Img1, tab3Img1Name, advType);
						if (null != eventImage) {
							contents.append("tab3Img1Name=").append(eventImage.getUuid()).append(eventImage.getImgType())
									.append("\n").append("tab3Img1Folder=").append(today).append("\n");
						}
					}
					if (null == tab3Img2) {
						contents.append("tab3Img2Name=").append(tab3Img2Name).append("\n").append("tab3Img2Folder=").append(
								tab3Img2Folder).append("\n");
					} else {
						eventImage = saveImgFile(tab3Img2, tab3Img2Name, advType);
						if (null != eventImage) {
							contents.append("tab3Img2Name=").append(eventImage.getUuid()).append(eventImage.getImgType())
									.append("\n").append("tab3Img2Folder=").append(today).append("\n");
						}
					}

					if (null == tab3Img3) {
						contents.append("tab3Img3Name=").append(tab3Img3Name).append("\n").append("tab3Img3Folder=").append(
								tab3Img3Folder).append("\n");
					} else {
						eventImage = saveImgFile(tab3Img3, tab3Img3Name, advType);
						if (null != eventImage) {
							contents.append("tab3Img3Name=").append(eventImage.getUuid()).append(eventImage.getImgType())
									.append("\n").append("tab3Img3Folder=").append(today).append("\n");
						}
					}

					if (null == tab3Img4) {
						contents.append("tab3Img4Name=").append(tab3Img4Name).append("\n").append("tab3Img4Folder=").append(
								tab3Img4Folder).append("\n");
					} else {
						eventImage = saveImgFile(tab3Img4, tab3Img4Name, advType);
						if (null != eventImage) {
							contents.append("tab3Img4Name=").append(eventImage.getUuid()).append(eventImage.getImgType())
									.append("\n").append("tab3Img4Folder=").append(today).append("\n");
						}
					}
				}

				contents.append("tab1Img1Link=").append(checkURL(tab1Img1Link)).append("\n");
				contents.append("tab1Img2Link=").append(checkURL(tab1Img2Link)).append("\n");
				contents.append("tab1Img3Link=").append(checkURL(tab1Img3Link)).append("\n");
				contents.append("tab1Img4Link=").append(checkURL(tab1Img4Link)).append("\n");

				contents.append("tab2Img1Link=").append(checkURL(tab2Img1Link)).append("\n");
				contents.append("tab2Img2Link=").append(checkURL(tab2Img2Link)).append("\n");
				contents.append("tab2Img3Link=").append(checkURL(tab2Img3Link)).append("\n");
				contents.append("tab2Img4Link=").append(checkURL(tab2Img4Link)).append("\n");

				contents.append("tab3Img1Link=").append(checkURL(tab3Img1Link)).append("\n");
				contents.append("tab3Img2Link=").append(checkURL(tab3Img2Link)).append("\n");
				contents.append("tab3Img3Link=").append(checkURL(tab3Img3Link)).append("\n");
				contents.append("tab3Img4Link=").append(checkURL(tab3Img4Link)).append("\n");

				contents.append("tab1Img1adWord=").append(StringUtils.defaultString(tab1Img1adWord)).append("\n");
				contents.append("tab1Img2adWord=").append(StringUtils.defaultString(tab1Img2adWord)).append("\n");
				contents.append("tab1Img3adWord=").append(StringUtils.defaultString(tab1Img3adWord)).append("\n");
				contents.append("tab1Img4adWord=").append(StringUtils.defaultString(tab1Img4adWord)).append("\n");

				contents.append("tab2Img1adWord=").append(StringUtils.defaultString(tab2Img1adWord)).append("\n");
				contents.append("tab2Img2adWord=").append(StringUtils.defaultString(tab2Img2adWord)).append("\n");
				contents.append("tab2Img3adWord=").append(StringUtils.defaultString(tab2Img3adWord)).append("\n");
				contents.append("tab2Img4adWord=").append(StringUtils.defaultString(tab2Img4adWord)).append("\n");

				contents.append("tab3Img1adWord=").append(StringUtils.defaultString(tab3Img1adWord)).append("\n");
				contents.append("tab3Img2adWord=").append(StringUtils.defaultString(tab3Img2adWord)).append("\n");
				contents.append("tab3Img3adWord=").append(StringUtils.defaultString(tab3Img3adWord)).append("\n");
				contents.append("tab3Img4adWord=").append(StringUtils.defaultString(tab3Img4adWord)).append("\n");

				if (StringUtils.isBlank(advId)) {
					advertise = new GenerateAdvertise();
					position = new GeneratePosition();
					content = new GenerateContent();
				} else {
					advertise = generateService.get(Long.parseLong(advId));
					position = generateService.getGeneratePositionByAdvId(Long.parseLong(advId)).get(0);
					content = generateService.getGenerateContentByAdvId(Long.parseLong(advId)).get(0);
				}
				// set advertise
				advertise.setAdvType(advType);
				advertise.setAdvName(advName.trim());
				advertise.setStartDate(PATTERN_DATE_FORMAT.parse(startDate + " " + startTime + ":00"));
				advertise.setEndDate(PATTERN_DATE_FORMAT.parse(endDate + " " + endTime + ":59"));
				advertise.setAdvStatus(advStatus);
				content.setContents(contents.toString());
				if (StringUtils.countMatches(content.getContents(), "Folder") == 12) {
					if (StringUtils.isBlank(advId)) {
						result = generateService.saveGenerateCombine(advertise, position, content);
					} else {
						result = generateService.updateGenerateCombine(advertise, position, content);
					}
				} else {
					result = false;
				}
				contents.setLength(0);
				// 存檔後立刻執行產生檔案的邏輯
				generateService.generateIdxGoldFourV2(null);
				if (!result) {
					return "editIdxGoldFourAdvV2";
				} else {
					advId = advertise.getId().toString();
					addActionMessage("储存成功");
				}
			}
		}
		return editIdxGoldFourAdvV2();
	}

	EventImage saveImgFile(File imgFile, String fileName, String advType) throws Exception {
		try {
			eventImage = new EventImage();
			eventImage.setImgType(fileName.substring(fileName.lastIndexOf("."), fileName.length()));
			eventImage = generateService.saveEventImage(eventImage);
			boolean result = GenerateHelper.uploadImage(eventImage, imgFile, advType);
			if (result) {
				return eventImage;
			} else {
				return null;
			}
		} catch (Exception e) {
			logger.info("exception :{}", e.getMessage());
		}
		return null;
	}

	/**
	 * @param advId the advId to set
	 */
	public void setAdvId(String advId) {
		this.advId = advId;
	}

	/**
	 * @param advName the advName to set
	 */
	public void setAdvName(String advName) {
		this.advName = advName;
	}

	/**
	 * @param advStatus the advStatus to set
	 */
	public void setAdvStatus(String advStatus) {
		this.advStatus = advStatus;
	}

	/**
	 * @param advType the advType to set
	 */
	public void setAdvType(String advType) {
		this.advType = advType;
	}

	/**
	 * @param content the content to set
	 */
	public void setContent(GenerateContent content) {
		this.content = content;
	}

	/**
	 * @param endDate the endDate to set
	 */
	public void setEndDate(String endDate) {
		this.endDate = endDate;
	}

	public void setEndTime(String endTime) {
		this.endTime = endTime;
	}

	/**
	 * @param generateService the generateService to set
	 */
	public void setGenerateService(GenerateService generateService) {
		this.generateService = generateService;
	}

	/**
	 * @param startDate the startDate to set
	 */
	public void setStartDate(String startDate) {
		this.startDate = startDate;
	}

	public void setStartTime(String startTime) {
		this.startTime = startTime;
	}

	/**
	 * @param tab1Img1 the tab1Img1 to set
	 */
	public void setTab1Img1(File tab1Img1) {
		this.tab1Img1 = tab1Img1;
	}

	/**
	 * @param tab1Img1Folder the tab1Img1Folder to set
	 */
	public void setTab1Img1Folder(String tab1Img1Folder) {
		this.tab1Img1Folder = tab1Img1Folder;
	}

	/**
	 * @param tab1Img1Link the tab1Img1Link to set
	 */
	public void setTab1Img1Link(String tab1Img1Link) {
		this.tab1Img1Link = tab1Img1Link;
	}

	/**
	 * @param tab1Img1Name the tab1Img1Name to set
	 */
	public void setTab1Img1Name(String tab1Img1Name) {
		this.tab1Img1Name = tab1Img1Name;
	}

	/**
	 * @param tab1Img2 the tab1Img2 to set
	 */
	public void setTab1Img2(File tab1Img2) {
		this.tab1Img2 = tab1Img2;
	}

	/**
	 * @param tab1Img2Folder the tab1Img2Folder to set
	 */
	public void setTab1Img2Folder(String tab1Img2Folder) {
		this.tab1Img2Folder = tab1Img2Folder;
	}

	/**
	 * @param tab1Img2Link the tab1Img2Link to set
	 */
	public void setTab1Img2Link(String tab1Img2Link) {
		this.tab1Img2Link = tab1Img2Link;
	}

	/**
	 * @param tab1Img2Name the tab1Img2Name to set
	 */
	public void setTab1Img2Name(String tab1Img2Name) {
		this.tab1Img2Name = tab1Img2Name;
	}

	/**
	 * @param tab1Img3 the tab1Img3 to set
	 */
	public void setTab1Img3(File tab1Img3) {
		this.tab1Img3 = tab1Img3;
	}

	/**
	 * @param tab1Img3Folder the tab1Img3Folder to set
	 */
	public void setTab1Img3Folder(String tab1Img3Folder) {
		this.tab1Img3Folder = tab1Img3Folder;
	}

	/**
	 * @param tab1Img3Link the tab1Img3Link to set
	 */
	public void setTab1Img3Link(String tab1Img3Link) {
		this.tab1Img3Link = tab1Img3Link;
	}

	/**
	 * @param tab1Img3Name the tab1Img3Name to set
	 */
	public void setTab1Img3Name(String tab1Img3Name) {
		this.tab1Img3Name = tab1Img3Name;
	}

	/**
	 * @param tab1Img4 the tab1Img4 to set
	 */
	public void setTab1Img4(File tab1Img4) {
		this.tab1Img4 = tab1Img4;
	}

	/**
	 * @param tab1Img4Folder the tab1Img4Folder to set
	 */
	public void setTab1Img4Folder(String tab1Img4Folder) {
		this.tab1Img4Folder = tab1Img4Folder;
	}

	/**
	 * @param tab1Img4Link the tab1Img4Link to set
	 */
	public void setTab1Img4Link(String tab1Img4Link) {
		this.tab1Img4Link = tab1Img4Link;
	}

	/**
	 * @param tab1Img4Name the tab1Img4Name to set
	 */
	public void setTab1Img4Name(String tab1Img4Name) {
		this.tab1Img4Name = tab1Img4Name;
	}

	/**
	 * @param tab2Img1 the tab2Img1 to set
	 */
	public void setTab2Img1(File tab2Img1) {
		this.tab2Img1 = tab2Img1;
	}

	/**
	 * @param tab2Img1Folder the tab2Img1Folder to set
	 */
	public void setTab2Img1Folder(String tab2Img1Folder) {
		this.tab2Img1Folder = tab2Img1Folder;
	}

	/**
	 * @param tab2Img1Link the tab2Img1Link to set
	 */
	public void setTab2Img1Link(String tab2Img1Link) {
		this.tab2Img1Link = tab2Img1Link;
	}

	/**
	 * @param tab2Img1Name the tab2Img1Name to set
	 */
	public void setTab2Img1Name(String tab2Img1Name) {
		this.tab2Img1Name = tab2Img1Name;
	}

	/**
	 * @param tab2Img2 the tab2Img2 to set
	 */
	public void setTab2Img2(File tab2Img2) {
		this.tab2Img2 = tab2Img2;
	}

	/**
	 * @param tab2Img2Folder the tab2Img2Folder to set
	 */
	public void setTab2Img2Folder(String tab2Img2Folder) {
		this.tab2Img2Folder = tab2Img2Folder;
	}

	/**
	 * @param tab2Img2Link the tab2Img2Link to set
	 */
	public void setTab2Img2Link(String tab2Img2Link) {
		this.tab2Img2Link = tab2Img2Link;
	}

	/**
	 * @param tab2Img2Name the tab2Img2Name to set
	 */
	public void setTab2Img2Name(String tab2Img2Name) {
		this.tab2Img2Name = tab2Img2Name;
	}

	/**
	 * @param tab2Img3 the tab2Img3 to set
	 */
	public void setTab2Img3(File tab2Img3) {
		this.tab2Img3 = tab2Img3;
	}

	/**
	 * @param tab2Img3Folder the tab2Img3Folder to set
	 */
	public void setTab2Img3Folder(String tab2Img3Folder) {
		this.tab2Img3Folder = tab2Img3Folder;
	}

	/**
	 * @param tab2Img3Link the tab2Img3Link to set
	 */
	public void setTab2Img3Link(String tab2Img3Link) {
		this.tab2Img3Link = tab2Img3Link;
	}

	/**
	 * @param tab2Img3Name the tab2Img3Name to set
	 */
	public void setTab2Img3Name(String tab2Img3Name) {
		this.tab2Img3Name = tab2Img3Name;
	}

	/**
	 * @param tab2Img4 the tab2Img4 to set
	 */
	public void setTab2Img4(File tab2Img4) {
		this.tab2Img4 = tab2Img4;
	}

	/**
	 * @param tab2Img4Folder the tab2Img4Folder to set
	 */
	public void setTab2Img4Folder(String tab2Img4Folder) {
		this.tab2Img4Folder = tab2Img4Folder;
	}

	/**
	 * @param tab2Img4Link the tab2Img4Link to set
	 */
	public void setTab2Img4Link(String tab2Img4Link) {
		this.tab2Img4Link = tab2Img4Link;
	}

	/**
	 * @param tab2Img4Name the tab2Img4Name to set
	 */
	public void setTab2Img4Name(String tab2Img4Name) {
		this.tab2Img4Name = tab2Img4Name;
	}

	/**
	 * @param tab3Img1 the tab3Img1 to set
	 */
	public void setTab3Img1(File tab3Img1) {
		this.tab3Img1 = tab3Img1;
	}

	/**
	 * @param tab3Img1Folder the tab3Img1Folder to set
	 */
	public void setTab3Img1Folder(String tab3Img1Folder) {
		this.tab3Img1Folder = tab3Img1Folder;
	}

	/**
	 * @param tab3Img1Link the tab3Img1Link to set
	 */
	public void setTab3Img1Link(String tab3Img1Link) {
		this.tab3Img1Link = tab3Img1Link;
	}

	/**
	 * @param tab3Img1Name the tab3Img1Name to set
	 */
	public void setTab3Img1Name(String tab3Img1Name) {
		this.tab3Img1Name = tab3Img1Name;
	}

	/**
	 * @param tab3Img2 the tab3Img2 to set
	 */
	public void setTab3Img2(File tab3Img2) {
		this.tab3Img2 = tab3Img2;
	}

	/**
	 * @param tab3Img2Folder the tab3Img2Folder to set
	 */
	public void setTab3Img2Folder(String tab3Img2Folder) {
		this.tab3Img2Folder = tab3Img2Folder;
	}

	/**
	 * @param tab3Img2Link the tab3Img2Link to set
	 */
	public void setTab3Img2Link(String tab3Img2Link) {
		this.tab3Img2Link = tab3Img2Link;
	}

	/**
	 * @param tab3Img2Name the tab3Img2Name to set
	 */
	public void setTab3Img2Name(String tab3Img2Name) {
		this.tab3Img2Name = tab3Img2Name;
	}

	/**
	 * @param tab3Img3 the tab3Img3 to set
	 */
	public void setTab3Img3(File tab3Img3) {
		this.tab3Img3 = tab3Img3;
	}

	/**
	 * @param tab3Img3Folder the tab3Img3Folder to set
	 */
	public void setTab3Img3Folder(String tab3Img3Folder) {
		this.tab3Img3Folder = tab3Img3Folder;
	}

	/**
	 * @param tab3Img3Link the tab3Img3Link to set
	 */
	public void setTab3Img3Link(String tab3Img3Link) {
		this.tab3Img3Link = tab3Img3Link;
	}

	/**
	 * @param tab3Img3Name the tab3Img3Name to set
	 */
	public void setTab3Img3Name(String tab3Img3Name) {
		this.tab3Img3Name = tab3Img3Name;
	}

	/**
	 * @param tab3Img4 the tab3Img4 to set
	 */
	public void setTab3Img4(File tab3Img4) {
		this.tab3Img4 = tab3Img4;
	}

	/**
	 * @param tab3Img4Folder the tab3Img4Folder to set
	 */
	public void setTab3Img4Folder(String tab3Img4Folder) {
		this.tab3Img4Folder = tab3Img4Folder;
	}

	/**
	 * @param tab3Img4Link the tab3Img4Link to set
	 */
	public void setTab3Img4Link(String tab3Img4Link) {
		this.tab3Img4Link = tab3Img4Link;
	}

	/**
	 * @param tab3Img4Name the tab3Img4Name to set
	 */
	public void setTab3Img4Name(String tab3Img4Name) {
		this.tab3Img4Name = tab3Img4Name;
	}

	public String getTab1Img1adWord() {
		return tab1Img1adWord;
	}

	public void setTab1Img1adWord(String tab1Img1adWord) {
		this.tab1Img1adWord = tab1Img1adWord;
	}

	public String getTab1Img2adWord() {
		return tab1Img2adWord;
	}

	public void setTab1Img2adWord(String tab1Img2adWord) {
		this.tab1Img2adWord = tab1Img2adWord;
	}

	public String getTab1Img3adWord() {
		return tab1Img3adWord;
	}

	public void setTab1Img3adWord(String tab1Img3adWord) {
		this.tab1Img3adWord = tab1Img3adWord;
	}

	public String getTab1Img4adWord() {
		return tab1Img4adWord;
	}

	public void setTab1Img4adWord(String tab1Img4adWord) {
		this.tab1Img4adWord = tab1Img4adWord;
	}

	public String getTab2Img1adWord() {
		return tab2Img1adWord;
	}

	public void setTab2Img1adWord(String tab2Img1adWord) {
		this.tab2Img1adWord = tab2Img1adWord;
	}

	public String getTab2Img2adWord() {
		return tab2Img2adWord;
	}

	public void setTab2Img2adWord(String tab2Img2adWord) {
		this.tab2Img2adWord = tab2Img2adWord;
	}

	public String getTab2Img3adWord() {
		return tab2Img3adWord;
	}

	public void setTab2Img3adWord(String tab2Img3adWord) {
		this.tab2Img3adWord = tab2Img3adWord;
	}

	public String getTab2Img4adWord() {
		return tab2Img4adWord;
	}

	public void setTab2Img4adWord(String tab2Img4adWord) {
		this.tab2Img4adWord = tab2Img4adWord;
	}

	public String getTab3Img1adWord() {
		return tab3Img1adWord;
	}

	public void setTab3Img1adWord(String tab3Img1adWord) {
		this.tab3Img1adWord = tab3Img1adWord;
	}

	public String getTab3Img2adWord() {
		return tab3Img2adWord;
	}

	public void setTab3Img2adWord(String tab3Img2adWord) {
		this.tab3Img2adWord = tab3Img2adWord;
	}

	public String getTab3Img3adWord() {
		return tab3Img3adWord;
	}

	public void setTab3Img3adWord(String tab3Img3adWord) {
		this.tab3Img3adWord = tab3Img3adWord;
	}

	public String getTab3Img4adWord() {
		return tab3Img4adWord;
	}

	public void setTab3Img4adWord(String tab3Img4adWord) {
		this.tab3Img4adWord = tab3Img4adWord;
	}

}
